(function($, doc) {
	$.plusReady(function() {
		mui.init();
		var user = app.getState();
		var uid = user.user_id;
		var currentmoney = 10;
		$('#selecttype').on('tap','span', function(){
			//console.log(this.id);
			doc.querySelector('.click').classList.remove('click');
			this.classList.add('click');
			currentmoney = this.innerHTML*1;
		});
		
		doc.getElementById('create').addEventListener('tap', function(){
			var passwd = doc.getElementById('passwd').value;
			if(!passwd) {
				$.alert("交易密码不能为空！");
				return;
			}
			var wallet = ethscan.getWallet('eth');
			if(!wallet || !wallet.address){
				$.alert("请创建钱包！");
				return;
			}
			var postdata = {
				uid : uid,
				trade_pwd : passwd,
				trade_money : currentmoney,
				money_type : defaultCoinAddr,
				buy_address : wallet.address
			};
			
			var s = apiurl + "order/tradeBuy?";
			for(var p in postdata) {
				s += p + '=' + postdata[p] + '&';
			}
			console.log(s);
			$.post(apiurl + "order/tradeBuy", postdata, function(res){
				console.log(JSON.stringify(res));
				if(res.status && res.status > 0) {
					$.openWindow({url : 'order_list.html', id : 'order_list'});
				}else{
					$.toast('创建订单失败');
				}
			});
		});
	});
	
}(mui, document));